home *** CD-ROM | disk | FTP | other *** search
- Path: news.wwa.com!rmartin
- From: rmartin@oma.com (Robert C. Martin)
- Newsgroups: comp.lang.smalltalk,comp.object,comp.lang.c++,comp.lang.java
- Subject: Re: The Good, the Bad, the Ugly, and the Wicked ...
- Followup-To: comp.lang.smalltalk,comp.object,comp.lang.c++,comp.lang.java
- Date: 10 Apr 1996 18:33:35 GMT
- Organization: Object Mentor
- Message-ID: <RMARTIN.96Apr10133335@rcm.oma.com>
- References: <31570B8E.5A12@vmark.com> <4je5rq$7qg@mimas.brunel.ac.uk>
- <4jes0t$gth@decaxp.HARVARD.EDU> <31630E30.5A02@oma.com>
- <4kbq3q$1i8@gaia.ns.utk.edu> <JSA.96Apr9131057@organon.com>
- NNTP-Posting-Host: rcm.oma.com
- In-reply-to: jsa@organon.com's message of Tue, 9 Apr 1996 17:10:57 GMT
-
-
- Robert C. Martin (rmartin@oma.com) wrote:
-
- > : Malloc and new can *always* be made to be deterministic. That is
- > : one of the major attractions to manual memory management in
- > : real time systems. You can use malloc/free (new/delete) pairs which are
- > : 100% predictable.
- >
-
- mbk@caffeine.engr.utk.edu (Matt Kennel) writes:
- > Are they? Have you gone through the all the possible orderings of
- > previous 'new' and 'malloc' so that you ***KNOW*** exactly
- > what the internal heap structures are so that subsequent calls to
- > 'malloc' and 'new' and 'free' take a known amount of time?
-
- jsa@organon.com (Jon S Anthony) writes:
-
- Actually, it is even worse than you are suggesting as Malloc/new and
- free are not necessarily very predictable and can exhibit "bad" behavior
- depending on their use.
-
- You missed my point. new/delete can *always be made* to be completely
- deterministic. Consider:
-
- struct block
- {
- block* link;
- char space[100];
- };
-
- static block freestore[1000];
- static int allocPoint = 0;
- static block* freeList = 0;
-
- void* operator new(size_t s)
- {
- void* p = 0;
- if (s <= sizeof(block)) // not too big.
- {
- if (freeList)
- {
- p = freeList;
- freeList=freeList->link;
- }
- else if (allocPoint < 1000)
- {
- p = freestore+allocPoint++;
- }
- }
- return p;
- };
-
- void operator delete(void* p)
- {
- block* bp = (block*)p;
- bp->link = freeList;
- freeList = bp;
- };
-
- Now, this example is very very simplistic, (and I didn't compile it so it
- probably has some errors in it) however it provides a version of new
- and delete that are almost complete deterministic. The only ambiguity
- occurs when the freeList is empty. Even this small non-determinism
- could be eliminated if the freeList were linked up with all 1000
- blocks prior the start of the program.
-
- This is a typical strategy in real time systems. Note that one trades
- determinism for memory inefficiency. In the system above, even when
- somebody just wants 5 bytes, they still get all sizeof(block) bytes.
- This can be mitigated by creating a tiered structure. But it can
- never by perfectly eliminated.
-
- --
- Robert Martin | Design Consulting | Training courses offered:
- Object Mentor Assoc.| rmartin@oma.com | OOA/D, C++, Advanced OO
- 14619 N. Somerset Cr| Tel: (847) 918-1004 | Mgt. Overview of OOT
- Green Oaks IL 60048 | Fax: (847) 918-1023 | http://www.oma.com
-
-